﻿namespace Dcms.DAL
{
    using Dcms.BaseLib;
    using Dcms.IDAL;
    using Dcms.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;

    public class Dcms_JobSeekerDAL : IDcms_JobSeekerDAL
    {
        public Dcms_JobSeekerModel AddModel(Dcms_JobSeekerModel model)
        {
            string sQLString = "insert into Dcms_JobSeeker(Js_Identity,Js_Password,Js_RealName,Js_Sex,Js_Address,Js_Marry,Js_Birth,Js_Tel,Js_National,Js_FamilyTel,Js_Email,Js_FirstContacter,Js_FirstContacterTel,Js_WorkTime,Js_ForeignLanguage,Js_Computer,Js_WorkPlace,Js_PayDemands,Js_AboutEdu,Js_AboutWork,Js_AboutTrain,Js_AboutFamily,Js_AddTime,Js_HighEdu) values(@Js_Identity,@Js_Password,@Js_RealName,@Js_Sex,@Js_Address,@Js_Marry,@Js_Birth,@Js_Tel,@Js_National,@Js_FamilyTel,@Js_Email,@Js_FirstContacter,@Js_FirstContacterTel,@Js_WorkTime,@Js_ForeignLanguage,@Js_Computer,@Js_WorkPlace,@Js_PayDemands,@Js_AboutEdu,@Js_AboutWork,@Js_AboutTrain,@Js_AboutFamily,@Js_AddTime,@Js_HighEdu) SELECT @NewId=@@Identity";
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@NewId", SqlDbType.Int), new SqlParameter("@Js_Identity", SqlDbType.VarChar), new SqlParameter("@Js_Password", SqlDbType.VarChar), new SqlParameter("@Js_RealName", SqlDbType.VarChar), new SqlParameter("@Js_Sex", SqlDbType.TinyInt), new SqlParameter("@Js_Address", SqlDbType.VarChar), new SqlParameter("@Js_Marry", SqlDbType.TinyInt), new SqlParameter("@Js_Birth", SqlDbType.DateTime), new SqlParameter("@Js_Tel", SqlDbType.VarChar), new SqlParameter("@Js_National", SqlDbType.VarChar), new SqlParameter("@Js_FamilyTel", SqlDbType.VarChar), new SqlParameter("@Js_Email", SqlDbType.VarChar), new SqlParameter("@Js_FirstContacter", SqlDbType.VarChar), new SqlParameter("@Js_FirstContacterTel", SqlDbType.VarChar), new SqlParameter("@Js_WorkTime", SqlDbType.VarChar), new SqlParameter("@Js_ForeignLanguage", SqlDbType.VarChar), 
                new SqlParameter("@Js_Computer", SqlDbType.VarChar), new SqlParameter("@Js_WorkPlace", SqlDbType.VarChar), new SqlParameter("@Js_PayDemands", SqlDbType.VarChar), new SqlParameter("@Js_AboutEdu", SqlDbType.Text), new SqlParameter("@Js_AboutWork", SqlDbType.Text), new SqlParameter("@Js_AboutTrain", SqlDbType.Text), new SqlParameter("@Js_AboutFamily", SqlDbType.Text), new SqlParameter("@Js_AddTime", SqlDbType.DateTime), new SqlParameter("@Js_HighEdu", SqlDbType.VarChar)
             };
            cmdParms[0].Direction = ParameterDirection.Output;
            cmdParms[1].Value = model.Js_Identity;
            cmdParms[2].Value = model.Js_Password;
            cmdParms[3].Value = model.Js_RealName;
            cmdParms[4].Value = model.Js_Sex;
            cmdParms[5].Value = model.Js_Address;
            cmdParms[6].Value = model.Js_Marry;
            cmdParms[7].Value = model.Js_Birth;
            cmdParms[8].Value = model.Js_Tel;
            cmdParms[9].Value = model.Js_National;
            cmdParms[10].Value = model.Js_FamilyTel;
            cmdParms[11].Value = model.Js_Email;
            cmdParms[12].Value = model.Js_FirstContacter;
            cmdParms[13].Value = model.Js_FirstContacterTel;
            cmdParms[14].Value = model.Js_WorkTime;
            cmdParms[15].Value = model.Js_ForeignLanguage;
            cmdParms[0x10].Value = model.Js_Computer;
            cmdParms[0x11].Value = model.Js_WorkPlace;
            cmdParms[0x12].Value = model.Js_PayDemands;
            cmdParms[0x13].Value = model.Js_AboutEdu;
            cmdParms[20].Value = model.Js_AboutWork;
            cmdParms[0x15].Value = model.Js_AboutTrain;
            cmdParms[0x16].Value = model.Js_AboutFamily;
            cmdParms[0x17].Value = model.Js_AddTime;
            cmdParms[0x18].Value = model.Js_HighEdu;
            SqlHelper.ExecuteSql(sQLString, cmdParms);
            model.Js_Id = (int) cmdParms[0].Value;
            return model;
        }

        public IList<Dcms_JobSeekerModel> DataSetToList(DataSet ds)
        {
            IList<Dcms_JobSeekerModel> list = new List<Dcms_JobSeekerModel>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                Dcms_JobSeekerModel item = new Dcms_JobSeekerModel();
                if (ds.Tables[0].Rows[i]["Js_Id"].ToString() != "") item.Js_Id = int.Parse(ds.Tables[0].Rows[i]["Js_Id"].ToString());
                item.Js_Identity = ds.Tables[0].Rows[i]["Js_Identity"].ToString();
                item.Js_Password = ds.Tables[0].Rows[i]["Js_Password"].ToString();
                item.Js_RealName = ds.Tables[0].Rows[i]["Js_RealName"].ToString();
                if (ds.Tables[0].Rows[i]["Js_Sex"].ToString() != "") item.Js_Sex = int.Parse(ds.Tables[0].Rows[i]["Js_Sex"].ToString());
                item.Js_Address = ds.Tables[0].Rows[i]["Js_Address"].ToString();
                if (ds.Tables[0].Rows[i]["Js_Marry"].ToString() != "") item.Js_Marry = int.Parse(ds.Tables[0].Rows[i]["Js_Marry"].ToString());
                if (ds.Tables[0].Rows[i]["Js_Birth"].ToString() != "") item.Js_Birth = DateTime.Parse(ds.Tables[0].Rows[i]["Js_Birth"].ToString());
                item.Js_Tel = ds.Tables[0].Rows[i]["Js_Tel"].ToString();
                item.Js_National = ds.Tables[0].Rows[i]["Js_National"].ToString();
                item.Js_FamilyTel = ds.Tables[0].Rows[i]["Js_FamilyTel"].ToString();
                item.Js_Email = ds.Tables[0].Rows[i]["Js_Email"].ToString();
                item.Js_FirstContacter = ds.Tables[0].Rows[i]["Js_FirstContacter"].ToString();
                item.Js_FirstContacterTel = ds.Tables[0].Rows[i]["Js_FirstContacterTel"].ToString();
                item.Js_WorkTime = ds.Tables[0].Rows[i]["Js_WorkTime"].ToString();
                item.Js_ForeignLanguage = ds.Tables[0].Rows[i]["Js_ForeignLanguage"].ToString();
                item.Js_Computer = ds.Tables[0].Rows[i]["Js_Computer"].ToString();
                item.Js_WorkPlace = ds.Tables[0].Rows[i]["Js_WorkPlace"].ToString();
                item.Js_PayDemands = ds.Tables[0].Rows[i]["Js_PayDemands"].ToString();
                item.Js_AboutEdu = ds.Tables[0].Rows[i]["Js_AboutEdu"].ToString();
                item.Js_AboutWork = ds.Tables[0].Rows[i]["Js_AboutWork"].ToString();
                item.Js_AboutTrain = ds.Tables[0].Rows[i]["Js_AboutTrain"].ToString();
                item.Js_AboutFamily = ds.Tables[0].Rows[i]["Js_AboutFamily"].ToString();
                item.Js_HighEdu = ds.Tables[0].Rows[i]["Js_HighEdu"].ToString();
                if (ds.Tables[0].Rows[i]["Js_AddTime"].ToString() != "") item.Js_AddTime = DateTime.Parse(ds.Tables[0].Rows[i]["Js_AddTime"].ToString());
                list.Add(item);
            }
            return list;
        }

        public void DeleteModelByID(int ID)
        {
            string sQLString = "delete from Dcms_JobSeeker where Js_Id=@Js_Id";
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@Js_Id", SqlDbType.Int) };
            cmdParms[0].Value = ID;
            SqlHelper.ExecuteSql(sQLString, cmdParms);
        }

        public string GetDataCount(string SqlStr)
        {
            return SqlHelper.GetNoteCount(SqlStr).ToString();
        }

        public IList<Dcms_JobSeekerModel> GetDataListByPage(string SqlStr, int CurPage, int PageSize)
        {
            return this.DataSetToList(SqlHelper.CreateDataSet(SqlStr, (CurPage - 1) * PageSize, PageSize));
        }

        public Dcms_JobSeekerModel GetModelByID(int ID)
        {
            string sQLString = "select * from Dcms_JobSeeker where Js_Id=@Js_Id";
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@Js_Id", SqlDbType.Int) };
            cmdParms[0].Value = ID;
            Dcms_JobSeekerModel model = new Dcms_JobSeekerModel();
            DataSet ds = SqlHelper.CreateDataSet(sQLString, cmdParms);
            IList<Dcms_JobSeekerModel> list = this.DataSetToList(ds);
            return ((list.Count > 0) ? list[0] : null);
        }

        public DataSet GetModelList()
        {
            string sql = "select * from Dcms_JobSeeker";
            return SqlHelper.CreateDataSet(sql);
        }

        public Dcms_JobSeekerModel Update(Dcms_JobSeekerModel model)
        {
            string sQLString = "update Dcms_JobSeeker set Js_Identity=@Js_Identity,Js_Password=@Js_Password,Js_RealName=@Js_RealName,Js_Sex=@Js_Sex,Js_Address=@Js_Address,Js_Marry=@Js_Marry,Js_Birth=@Js_Birth,Js_Tel=@Js_Tel,Js_National=@Js_National,Js_FamilyTel=@Js_FamilyTel,Js_Email=@Js_Email,Js_FirstContacter=@Js_FirstContacter,Js_FirstContacterTel=@Js_FirstContacterTel,Js_WorkTime=@Js_WorkTime,Js_ForeignLanguage=@Js_ForeignLanguage,Js_Computer=@Js_Computer,Js_WorkPlace=@Js_WorkPlace,Js_PayDemands=@Js_PayDemands,Js_AboutEdu=@Js_AboutEdu,Js_AboutWork=@Js_AboutWork,Js_AboutTrain=@Js_AboutTrain,Js_AboutFamily=@Js_AboutFamily,Js_AddTime=@Js_AddTime,Js_HighEdu=@Js_HighEdu where Js_Id=@Js_Id";
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@Js_Identity", SqlDbType.VarChar), new SqlParameter("@Js_Password", SqlDbType.VarChar), new SqlParameter("@Js_RealName", SqlDbType.VarChar), new SqlParameter("@Js_Sex", SqlDbType.TinyInt), new SqlParameter("@Js_Address", SqlDbType.VarChar), new SqlParameter("@Js_Marry", SqlDbType.TinyInt), new SqlParameter("@Js_Birth", SqlDbType.DateTime), new SqlParameter("@Js_Tel", SqlDbType.VarChar), new SqlParameter("@Js_National", SqlDbType.VarChar), new SqlParameter("@Js_FamilyTel", SqlDbType.VarChar), new SqlParameter("@Js_Email", SqlDbType.VarChar), new SqlParameter("@Js_FirstContacter", SqlDbType.VarChar), new SqlParameter("@Js_FirstContacterTel", SqlDbType.VarChar), new SqlParameter("@Js_WorkTime", SqlDbType.VarChar), new SqlParameter("@Js_ForeignLanguage", SqlDbType.VarChar), new SqlParameter("@Js_Computer", SqlDbType.VarChar), 
                new SqlParameter("@Js_WorkPlace", SqlDbType.VarChar), new SqlParameter("@Js_PayDemands", SqlDbType.VarChar), new SqlParameter("@Js_AboutEdu", SqlDbType.Text), new SqlParameter("@Js_AboutWork", SqlDbType.Text), new SqlParameter("@Js_AboutTrain", SqlDbType.Text), new SqlParameter("@Js_AboutFamily", SqlDbType.Text), new SqlParameter("@Js_AddTime", SqlDbType.DateTime), new SqlParameter("@Js_HighEdu", SqlDbType.VarChar), new SqlParameter("@Js_Id", SqlDbType.Int)
             };
            cmdParms[0].Value = model.Js_Identity;
            cmdParms[1].Value = model.Js_Password;
            cmdParms[2].Value = model.Js_RealName;
            cmdParms[3].Value = model.Js_Sex;
            cmdParms[4].Value = model.Js_Address;
            cmdParms[5].Value = model.Js_Marry;
            cmdParms[6].Value = model.Js_Birth;
            cmdParms[7].Value = model.Js_Tel;
            cmdParms[8].Value = model.Js_National;
            cmdParms[9].Value = model.Js_FamilyTel;
            cmdParms[10].Value = model.Js_Email;
            cmdParms[11].Value = model.Js_FirstContacter;
            cmdParms[12].Value = model.Js_FirstContacterTel;
            cmdParms[13].Value = model.Js_WorkTime;
            cmdParms[14].Value = model.Js_ForeignLanguage;
            cmdParms[15].Value = model.Js_Computer;
            cmdParms[0x10].Value = model.Js_WorkPlace;
            cmdParms[0x11].Value = model.Js_PayDemands;
            cmdParms[0x12].Value = model.Js_AboutEdu;
            cmdParms[0x13].Value = model.Js_AboutWork;
            cmdParms[20].Value = model.Js_AboutTrain;
            cmdParms[0x15].Value = model.Js_AboutFamily;
            cmdParms[0x16].Value = model.Js_AddTime;
            cmdParms[0x17].Value = model.Js_HighEdu;
            cmdParms[0x18].Value = model.Js_Id;
            SqlHelper.ExecuteSql(sQLString, cmdParms);
            return model;
        }
    }
}

